<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>jQuery-ajax实例</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>
<div>
    <input type="button" value="发送get请求" id="sendGetBtn"/><br>
    <input type="button" value="发送post请求" id="sendPostBtn"/><br>
</div>
<script>

    let address = {
        "uid": 22,
        "realname": "tester",
        "mobile": "13772653123",
        "province": "河南省",
        "city": "南阳",
        "zone": "宛城区",
        "street": "张井村188号"
    }

    $(function () {
        //发送get请求
        $("#sendGetBtn").click(function () {

            $.ajax({
                //请求方式
                type: "GET",
                //请求地址
                url: "https://www.simoniu.com/commons/items/130",
                //请求成功
                success: function (result) {
                    console.log(result.data);
                },
                //请求失败，包含具体的错误信息
                error: function (e) {
                    console.log(e.status);
                    console.log(e.responseText);
                }
            })
        })

        //发送post请求
        $("#sendPostBtn").click(function () {
            $.ajax({
                //请求方式
                type: "POST",
                //请求的媒体类型
                contentType: "application/json;charset=UTF-8",
                //请求地址
                url: "https://www.simoniu.com/commons/address/",
                //数据，json字符串
                data: JSON.stringify(address),
                //请求成功
                success: function (result) {
                    console.log(result);
                },
                //请求失败，包含具体的错误信息
                error: function (e) {
                    console.log(e.status);
                    console.log(e.responseText);
                }
            })
        })
    })

</script>
</body>
</html>


